package br.com.educa.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Months;

public class DateUtils {

	public static int getDia(Date data){
		return Integer.parseInt(new SimpleDateFormat("dd").format(data));
	}

	public static int getMes(Date data){
		return Integer.parseInt(new SimpleDateFormat("MM").format(data));
	}

	public static int getAno(Date data){
		return Integer.parseInt(new SimpleDateFormat("yyyy").format(data));
	}

	public static int intervaloEmDias(Date dataInicial, Date dataFinal){

		DateTime start = new DateTime(getAno(dataInicial), getMes(dataInicial), getDia(dataInicial), 0, 0, 0, 0);
		DateTime end = new DateTime(getAno(dataFinal), getMes(dataFinal), getDia(dataFinal), 0, 0, 0, 0);
		Days days = Days.daysBetween(start, end);
		return days.getDays();
	}

	public static int intervaloEmMeses(Date dataInicial, Date dataFinal){
		
		DateTime start = new DateTime(getAno(dataInicial), getMes(dataInicial), getDia(dataInicial), 0, 0, 0, 0);
		DateTime end = new DateTime(getAno(dataFinal), getMes(dataFinal), getDia(dataFinal), 0, 0, 0, 0);
		Months months = Months.monthsBetween(start, end);
		return months.getMonths();
	}

}
